package com.jingdianjichi.oss.config;

import com.jingdianjichi.oss.service.AliStorageAdapter;
import com.jingdianjichi.oss.service.MinioStorageAdapter;
import com.jingdianjichi.oss.service.StorageAdapter;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.annotation.Resource;

/**
 * ClassName:StorageConfig
 * Package:com.jingdianjichi.oss.config
 * Description:
 *
 * @Author fst
 * @Create 2024/10/3 21:42
 * @Version 1.0
 */
@Configuration
@RefreshScope
public class StorageConfig
{

    @Value("${storage.service.type}")
    private String storageType;


    @Bean
    @RefreshScope
    public StorageAdapter storageAdapter()
    {
        if("minio".equals(storageType))
        {
            return new MinioStorageAdapter();
        }
        else if("aliyun".equals(storageType))
        {
            return new AliStorageAdapter();
        }
        else
        {
            throw new IllegalArgumentException("未找到文件存储处理器");
        }
    }
}
